﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using PivotIO.XML;
using PivotWebsite.Controllers;
using System.Web.Http;

namespace PivotWebsite.Tests.Controllers
{
    [TestClass]
    public class CollectionPropertiesControllerTest
    {
        [TestInitialize]
        public void TestReset()
        {
            Utils.TestInit();
        }

        [TestCleanup]
        public void TestCleanup()
        {
            Utils.TestFinalize();
        }

        [TestMethod]
        [ExpectedException(typeof(HttpResponseException))]
        public void PutBadCollection()
        {
            var pc = new CollectionPropertiesController();
            pc.Put(1, "dude", "10");
        }
        [TestMethod]
        [ExpectedException(typeof(HttpResponseException))]
        public void PutBadProperty()
        {
            var tc = new CollectionsController();
            var p = tc.PutCollection("freak");
            var pc = new CollectionPropertiesController();
            pc.Put(p.Id, "dude", "10");
        }

        [TestMethod]
        [ExpectedException(typeof(HttpResponseException))]
        public void GetBadCollection()
        {
            var pc = new CollectionPropertiesController();
            pc.Get(1, "dude");
        }

        [TestMethod]
        [ExpectedException(typeof(HttpResponseException))]
        public void GetBadProperty()
        {
            var tc = new CollectionsController();
            var p = tc.PutCollection("freak");
            var pc = new CollectionPropertiesController();
            pc.Get(p.Id, "dude");
        }

        [TestMethod]
        public void GetEmptyDescrip()
        {
            var tc = new CollectionsController();
            var p = tc.PutCollection("freak");
            var pc = new CollectionPropertiesController();
            var v = pc.Get(p.Id, "Description");
            Assert.AreEqual("", v, "empty description");
        }

        [TestMethod]
        public void GetEmptyClass()
        {
            var tc = new CollectionsController();
            var p = tc.PutCollection("freak");
            var pc = new CollectionPropertiesController();
            var v = pc.Get(p.Id, "PartitionByFacet");
            Assert.AreEqual("", v, "empty class");
        }

        [TestMethod]
        public void GetDescrip()
        {
            var tc = new CollectionsController();
            var p = tc.PutCollection("freak");
            var pc = new CollectionPropertiesController();
            pc.Put(p.Id, "Description", "metoo and I think so");
            var v = pc.Get(p.Id, "Description");
            Assert.AreEqual("metoo and I think so", v, "empty description");
        }
        [TestMethod]
        public void GetDescripWithClear()
        {
            var tc = new CollectionsController();
            var p = tc.PutCollection("freak");
            var pc = new CollectionPropertiesController();
            pc.Put(p.Id, "Description", "metoo and I think so");
            CollectionInfoIO.ResetCache();
            var v = pc.Get(p.Id, "Description");
            Assert.AreEqual("metoo and I think so", v, "empty description");
        }

        [TestMethod]
        public void GetClass()
        {
            var tc = new CollectionsController();
            var p = tc.PutCollection("freak");
            var pc = new CollectionPropertiesController();
            pc.Put(p.Id, "PartitionByFacet", "Year");
            var v = pc.Get(p.Id, "PartitionByFacet");
            Assert.AreEqual("Year", v, "empty class");
        }
    }
}
